package com.neusoft.di.reactivecore;

import reactor.netty.http.server.HttpServer;

import java.io.IOException;

public class ReactiveNettyServer {


    public static void main(String[] args) throws IOException {

        HttpServer.create()   // Prepares an HTTP server ready for configuration
                .port(8081)    // Configures the port number as zero, this will let the system pick up
                // an ephemeral port when binding the server
                .route(routes ->
                        // The server will respond only on POST requests
                        // where the path starts with /test and then there is path parameter
                        routes.get("/test/{param}", (request, response) ->
                                {
                                    System.out.println("Received request: " + request.uri());
                                    return response.sendString(request.receive()
                                            .asString()
                                            .map(s -> s + ' ' + request.param("param") + '!')
                                            .log("http-server"));
                                }
                        )
                )

                .bindNow(); // Starts the server in a blocking fashion, and waits for it to finish its initialization

//        HttpHandler handler = null;
//        ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
//        HttpServer.create().host(host).port(port).handle(adapter).bindNow();
        System.in.read();
    }
}
